<?php
namespace App\Transformers;

use League\Fractal\TransformerAbstract;
use App\Model\OrderProduct;

class OrderProductTransformer extends TransformerAbstract{

    private static $status = [
        'un_done' => '未上菜',
        'done' => '已上菜',
        'cancel' => '已取消',
        'return' => '退菜'
    ];

    public function transform(OrderProduct $item){
        return [
            'id' => $item->id,
            'order_id' => $item->order_id,
            'total_amount' => $item->total_amount,
            'num' => $item->num,
            'serve_num' => $item->serve_num,
//            'return_num' => $item->return_num,
            'information' => json_decode($item->information, true),
            'status' => OrderProductTransformer::$status[$item->status],
            'created_at' =>$item->created_at->toDateTimeString()
        ];
    }
}